package com.MartynovichIgor.KnowledgeTest.tools.usertools;

import com.MartynovichIgor.KnowledgeTest.tools.testtools.TestController;
import java.io.IOException;
import java.util.ArrayList;
import java.util.ResourceBundle;

/**
 * Created by:
 * User: Igor Martynovich and Guzenko Igor
 * Date: 25.10.13
 */
public class User {
    private History userHistory;
    private String login;
    private String password;

    public User(String login, String password, ArrayList<Integer> shufledIndexes,
                ArrayList<Integer> loadedAnswers, ResourceBundle languageBundle, int currentQuestion) throws IOException {
        userHistory = new History(shufledIndexes, loadedAnswers, languageBundle, currentQuestion);
        this.login = login;
        this.password = password;
    }

    /**
     * Сохраняет историю.
     * @throws IOException
     */
    public void saveHistory() throws IOException {
        userHistory.save(this.login, this.password, getScore());
    }

    public History getHistory() {
        return userHistory;
    }

    /**
     * Метод возвращает число очков за тест.
     * @return
     */
    public int getScore() {
        int score = 0;
        for (int index = 0; index < TestController.COUNT_OF_QUESTIONS; index++) {
            if (userHistory.getUserAnswer(index) < 0) {
                score += 0;
            } else {
                score += userHistory.getUserAnswer(index);
            }

        }
        return score;
    }
}
